﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;
using System.Net;

namespace Marta.buchalska.wesele
{
    public partial class Contact : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        /// <summary>
        /// Wysłanie maila
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void sendBtn_Click(object sender, EventArgs e)
        {
            try
            {
                MailMessage mail = new MailMessage { From = new MailAddress(emailTextBox.Text) };
                mail.To.Add("kontakt@gardinimontania.pl");

                mail.Subject = "Kontakt " + NameTextBox.Text + company.Value != string.Empty ? company.Value : string.Empty;
                mail.SubjectEncoding = System.Text.Encoding.UTF8;
                mail.Body = messageBody.InnerText;
                mail.BodyEncoding = System.Text.Encoding.UTF8;


                SmtpClient smtp = new SmtpClient("mail.gardinimontania.pl")
                {
                    Credentials = new NetworkCredential("kontakt@gardinimontania.pl", "Ok56fap0M3")
                };
                smtp.Send(mail);
                Response.Redirect("~/AcceptEntryForm.aspx");
            }
            catch (Exception Exception)
            {
                Response.Write(Exception.Message);
            }
        }
    }
}